package diagramobjects;

import program.DatabaseConnection;
import utils.Color;
import utils.Point;

public class Text extends DiagramObject
{
	private Integer Id;
	private String Caption;
	private Point Position;
	private Double Alfa;
	private Color TColor;
	private Integer Size;

	
	public Text(String caption, Point position, Color color, Integer size) {
		super();
		Caption = caption;
		Position = position;
		TColor = color;
		Size = size;
	}
	
	public Text(String caption, Point position, Double Alfa,  Color color, Integer size) {
		super();
		Caption = caption;
		Position = position;
		TColor = color;
		Size = size;
	}
	
	public void Rotate(Double a)
	{
		Alfa = a;
	}
	
	public Double GetAlfa()
	{
		return Alfa;
	}
	
	public void AddToDatabase()
	{
		DatabaseConnection.AddText(ToDatabase());
	}
	
	public String ToDatabase()
	{
		String toReturn = Caption + "," +
						  Position.getX().toString() + "," +
						  Position.getY().toString() + "," +
						  Size.toString();
		return toReturn;
	}

	/**
	 * @return the caption
	 */
	public String getCaption()
	{
		return Caption;
	}

	/**
	 * @return the position
	 */
	public Point getPosition()
	{
		return Position;
	}
	
	public Integer getGraphicalLength()
	{
		return new Double(Caption.length()*Size*0.675).intValue();
	}
	
	public Integer getGraphicalHeight()
	{
		return Size/2;
	}
	
	public void setPosition(Point p)
	{
		Position = p;
	}
	
	public void setPosition(Integer x, Integer y)
	{
		Position.MoveTo(x, y);
	}
	
	
	
	public Integer getTextSize()
	{
		return Size;
	}


	public void setTextSize(Integer s)
	{
		Size = s;
	}
	

	
	public void MoveTo(Integer x, Integer y)
	{
		Position.setX(x-Caption.length()/2*5);
		Position.setY(y);
		
	}

	@Override
	public void MoveByVector(Integer vx, Integer vy)
	{
		Position.setX(Position.getX() + vx);
		Position.setY(Position.getY() + vy);
	}
	
	
}
